/**
 * @filename:OtherinspectController Apr 11, 2025
 * @project Wonder Vue Admin Api  1.1.0
 * Copyright(c) 2020 Wonder Co. Ltd. 
 * All right reserved. 
 */
package com.wonder.app.controller;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Date;
import java.util.Map;

import com.wonder.admin.domain.SysAdmin;
import com.wonder.admin.service.SysAdminService;
import com.wonder.app.domain.Otherinspect;
import com.wonder.app.service.OtherinspectService;
import com.wonder.app.request.OtherinspectRequest;
import com.wonder.framework.authorization.CheckAdminToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.wonder.common.common.AjaxMap;
import com.wonder.common.common.AjaxResult;
import com.wonder.common.common.CommonPage;
import com.wonder.common.utils.MessageUtils;
import com.wonder.common.utils.StringUtils;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;

import javax.servlet.http.HttpServletRequest;

/**
 * 
 * <p>说明： 其他入库质检API接口层</P>
 * @version: 1.1.0
 * @author: Wonder
 * @time    Apr 11, 2025
 *
 */
@Api(tags = "其他入库质检")
@RestController
@RequestMapping("/app/Otherinspect")
public class OtherinspectController {
	
	@Autowired
	private OtherinspectService otherinspectService;

	@Autowired
	private SysAdminService adminService;

	@Autowired
	private CheckAdminToken checkAdminToken;
	
	@ApiOperation(value = "其他入库质检列表")
	@RequestMapping(value = "/index", method = RequestMethod.POST)
	public Map<String,Object> index(@RequestBody OtherinspectRequest otherinspectRequest) {
		Page<Otherinspect> page = new Page<Otherinspect>(otherinspectRequest.getPage(), otherinspectRequest.getLimit());
		IPage<Otherinspect> list = otherinspectService.selectList(otherinspectRequest, page);
		
		Map<String,Object> retMap=new HashMap<>();
		retMap.put("data",CommonPage.restPage(list));
		
  
		return AjaxMap.success(retMap);
	}
	
	/**
	 * @explain 修改排序开关
	 * @param   entity
	 * @return  Boolean
	 * @author  Wonder
	 */
	@PostMapping("/updateExt")
	@ApiOperation(value = "修改排序开关", notes = "作者：Wonder")
	public AjaxResult<Otherinspect> updateExt(@RequestBody Otherinspect entity){
		if (null!=entity) {
			boolean rsg = otherinspectService.updateById(entity);
			if (rsg) {
				  return AjaxResult.success("system.updateSuccess");
			  }else {
				  return AjaxResult.failed("system.updateFailed");
			  }
		}else {
			return AjaxResult.failed("system.parameterError");
		}
	}
	
//	/**
//	 * @explain 查看对象明细
//	 * @param   map 对象参数：id
//	 * @return  JsonResult
//	 * @author  Wonder
//	 */
//	@PostMapping("/detail")
//	@ApiOperation(value = "获取其他入库质检对象明细", notes = "作者：Wonder")
//	public AjaxResult<Otherinspect> detail(@RequestBody Map<String,Object> map){
//	    if(map==null) return AjaxResult.failed("system.parameterError");
//		Long id=Long.parseLong(map.get("id").toString());
//		Otherinspect otherinspect=otherinspectService.getById(id);
//		if (null!=otherinspect ) {
//			 return AjaxResult.success(otherinspect);
//		}else {
//			 return AjaxResult.failed("system.parameterError");
//		}
//
//	}


	/**
	 * @explain 查看子项明细
	 * @param   map 对象参数：id
	 * @return  JsonResult
	 * @author  Wonder
	 */
	@ApiOperation(value = "查询otherinspect明细")
	@ResponseBody
	@PostMapping(value = "/otherinspectdetail")

	public AjaxResult<Map<String,Object>> getOtherInspectDetail(HttpServletRequest request, @RequestBody Map<String,Object> map) throws Exception{
		if (null == map){
			return AjaxResult.failed("system.parameterError");
		}
		Map<String,Object> data = otherinspectService.getOtherInspectDetail(map);
		if (null != data){
			return AjaxResult.success(data);
		} else {
			return AjaxResult.failed();
		}
	}


	@ApiOperation(value = "其它入检验单列表(手机端)")
	@RequestMapping(value = "/get_other_inspect_list", method = RequestMethod.POST)
	public AjaxResult<Map<String,Object>> getOtherInspectList(@RequestBody Map<String,Object> map) {

		Map<String,Object> data = otherinspectService.getOtherInspectList(map);
		if (null != data){
			return AjaxResult.success(data);
		} else {
			return AjaxResult.failed();
		}
	}

	/**
	 * @explain 查看入库质检子项明细(手机端)
	 * @param   map 对象参数：id
	 * @return  JsonResult
	 * @author  Wonder
	 */
	@ApiOperation(value = "查询明细(手机端)")
	@ResponseBody
	@PostMapping(value = "/get_other_inspect_detail")

	public AjaxResult<Map<String,Object>> getInspectDetailPhone(HttpServletRequest request, @RequestBody Map<String,Object> map) throws Exception{

		Map<String,Object> data = otherinspectService.getInspectDetailPhone(map);
		if (null != data){
			return AjaxResult.success(data);
		} else {
			return AjaxResult.failed();
		}
	}

	/**
	 * 修改检验单详情是否检验的状态
	 * @param
	 * @return
	 * @throws Exception
	 */
	@ApiOperation(value = "修改检验单详情是否检验的状态")
	@ResponseBody
	@PostMapping(value = "/change_other_inspect_isChecked")
	public AjaxResult<?> changeOtherInspectIsChecked(HttpServletRequest request, @RequestBody Map<String,Object> map) throws Exception {
		String token = checkAdminToken.getTokenFormRequest(request);
		SysAdmin user = adminService.getAdminByToken(token);
		String userName = user.getName();
		boolean result = otherinspectService.changeOtherInspectIsChecked(userName,map);
		if (result) {
			return AjaxResult.success(result);
		}else {
			return AjaxResult.failed("system.parameterError");
		}
	}

	/**
	 * 质检审核来料检验单
	 * @param
	 * @return
	 * @throws Exception
	 */
	@ApiOperation(value = "质检审核")
	@ResponseBody
	@PostMapping(value = "/audit_other_inspect")
	public AjaxResult<?> auditInspect(HttpServletRequest request, @RequestBody Map<String,Object> map) throws Exception {
		String token = checkAdminToken.getTokenFormRequest(request);
		SysAdmin user = adminService.getAdminByToken(token);
		String userName = user.getName();
		boolean result = otherinspectService.auditOtherInspect(userName,map);
		if (result ) {
			return AjaxResult.success(result);
		}else {
			return AjaxResult.failed("system.parameterError");
		}
	}
	
}